<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能停车场管理系统 - 删除停车场</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            background-image: url('../images/停车场图片1.png');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
     .popup {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
            width: 400px;
            text-align: center;
        }
     .popup h2 {
            margin-bottom: 20px;
            color: #00008B;
            font-weight: bold;
        }
     .form-group {
            margin-bottom: 15px;
        }
     .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }
     .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
     .form-group button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
     .form-group button:hover {
            background-color: #0056b3;
        }
     .message {
            text-align: center;
            margin-top: 15px;
            color: green;
        }
     .return-button {
            margin-top: 15px;
            padding: 8px 16px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
     .return-button:hover {
            background-color: #0056b3;
        }
     .error-message {
            color: red;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="popup">
        <h2>删除停车场信息</h2>
        <form id="deleteParkingForm">
            <div class="form-group">
                <label for="parkId">请输入要删除的停车场ID</label>
                <input type="text" id="parkId" v-model="parkIdValue" name="parkId" @blur="checkParkId" minlength="1" required pattern="\d+" oninput="validateInput(this)">
                <br />
                <label :style="{color:parkIdTipsColor}">{{parkIdTips}}</label>
            </div>
            <div class="form-group">
                <button type="button" @click="deleteParking" class="delete-parking-btn">删除停车场</button>
            </div>
        </form>
        <div class="message" id="message"></div>
        <button class="return-button" onclick="window.location.href = 'parking_info.html'">返回</button>
    </div>
    <script src="layui/layui.js" type="text/javascript"></script>
    <script src="js/vue.js" type="text/javascript"></script>
    <script src="js/jquery-3.6.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        let vm = new Vue({
            el: "#deleteParkingForm",
            data: {
                parkIdValue: "",
                parkIdTips: "",
                parkIdTipsColor: ""
            },
            methods: {
                checkParkId() {
                    let parkId = this.parkIdValue;
                    if (parkId.length < 1 || isNaN(parkId)) {
                        this.parkIdTips = "停车场ID不能为空且必须为数字";
                        this.parkIdTipsColor = "red";
                    } else {
                        this.parkIdTips = "";
                        this.parkIdTipsColor = "";
                    }
                },
                deleteParking() {
                    let url = "http://localhost:8080/parking/delete";
                    let parkId = parseInt(this.parkIdValue);
                    $.post(url, {parkId: parkId}, function (res) {
                        if (res.code === 200) {
                            document.getElementById('message').textContent = '删除成功';
                            document.getElementById('errorMessage').style.display = 'none';
                        } else {
                            document.getElementById('message').textContent = res.msg;
                            document.getElementById('errorMessage').style.display = 'block';
                        }
                    }, "JSON");
                }
            }
        });
        function validateInput(input) {
            var errorElement = document.getElementById(input.id + 'Error');
            errorElement.textContent = '';
        }
    </script>
</body>
</html>